package com.ktjy.util;

import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

/**
 * 将JSON格式的字符串数据输出
 *
 * @author LILIBO
 * @since 2021-06-24
 */
@Slf4j
public class WebUtil {

    /**
     * 将字符串输出到客户端
     *
     * @param response 输出对象
     * @param string 待输出的字符串
     */
    public static void writerString(HttpServletResponse response, String string) {
        try {
            response.setStatus(200);
            response.setContentType("application/json");
            response.setCharacterEncoding("UTF-8");
            response.getWriter().print(string);
        } catch (IOException e) {
            log.error("将字符串输出到客户端异常：", e);
        }
    }

}